/****************************************************************
 *  This file created by writerB.php on 03/26/2007 at 16:01:34  *
 ****************************************************************
 *  writerB.php created by Tonk (tonk@ctonk.com) in 2007        *
 ****************************************************************
 *                 General Document Information
 *
 *  File Name: timer.h
 *  Class Name: Timer
 *  Parent Classes: none
 *  Data members: 4
 *  Notes:
 ****************************************************************/

#ifndef __H_TIMER
#define __H_TIMER

#include <ctime>
#include <iostream>
#include <string>
#include "definitions.h"



class Timer { // ADT
	protected:
		// Protected data...
		int				_TimerID;	// Holds a unique value for every instantiation.
		std::string		_name;
		bool			_enabled;
		unsigned long	_interval;
		time_t			_when;

		// Protected methods...
		void			setTimerID( const int& TimerID );
		void			reset( void );
		void			reset( unsigned long int );
		void			reset( unsigned long int, unsigned long int );

	public:
		// Constructors...
		Timer();
		Timer( const Timer& );	// Doesn't change _TimerID
		virtual ~Timer();

		// Operators...
		Timer& operator = ( const Timer& );			// Doesn't change _TimerID
		bool operator == ( const Timer& ) const;	// Doesn't compare _TimerIDs
		bool operator < ( const Timer& ) const;		// Compares _TimerIDs
		bool operator > ( const Timer& ) const;		// Compares _TimerIDs

		// Public accessor methods...
		int				getTimerID( void ) const;
		void			setName( const std::string& name );
		std::string		getName( void ) const;
		void			setEnabled( const bool& enabled );
		bool			getEnabled( void ) const;
		void			setInterval( const unsigned long& interval );
		unsigned long	getInterval( void ) const;
		void			setWhen( const time_t& when );
		time_t			getWhen( void ) const;

		// General methods...
		bool			fire( void );
		virtual bool	execute( void ) = 0;

		// Static members and methods...
		static int	timerIndex;	// Used to create a unique id for every Timer object
		static int	numTimers;	// Keeps track of the total number of Timer objects
};

// Associated operators...
std::ostream& operator << ( std::ostream&, const Timer& );
std::ostream& operator << ( std::ostream&, const Timer* );

// Derived Timer classes...
class Tick: public Timer {
	protected:
		// No data.

	public:
		// Constructors...
		Tick();
		~Tick();

		// General methods...
		bool execute();
};

class Autosave: public Timer {
	protected:
		// No data.

	public:
		// Constructors...
		Autosave();
		~Autosave();

		// General methods...
		bool execute();
};

class Autoreboot: public Timer {
	protected:
		// Protected data...
		int					_stage;
		unsigned long int	_fiveMinuteWarning;
		unsigned long int	_thirtySecondWarning;
		unsigned long int	_countdownThree;
		unsigned long int	_countdownTwo;
		unsigned long int	_countdownOne;
		unsigned long int	_countdownOver;

		// Protected methods...
		void setWarningTimers();

	public:
		// Constructors...
		Autoreboot();
		~Autoreboot();

		// General methods...
		bool execute();
};

class Autobackup: public Timer {
	protected:
		// No data.

	public:
		// Constructors...
		Autobackup();
		~Autobackup();

		// General methods...
		bool execute();
};



#endif // __H_TIMER
